<template>
    <div class="box">
    <el-select v-model="value" placeholder="请选择" @change="$forceUpdate()">
      <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value">
      </el-option>
      
    </el-select>
    <el-button icon="el-icon-search" @click="select(value)" >开始租车</el-button>
    </div>
  </template>
  
  <script>
    export default {
      data() {
        return {
          options: [{
            value: '1',
            label: '天津市北辰区'
          }, {
            value: '2',
            label: '海南省海口市'
          }, {
            value: '3',
            label: '河北省廊坊市'
          
        }],
        // vehicles: [{
        //   // id:"1",
        //   // img:"https://www.sgmw.com.cn/bphgv/images/lunbo8.jpg",
        //   // price:"99"
        // }]
      }
    },
    methods:{
        select(value){
          localStorage.removeItem("car");
          if(value=='1'){
            this.$axios.post('/car/selectAddress',{

                address:'天津市北辰区',
              },
              {
              headers:{
                "token":JSON.parse(localStorage.getItem('user')).token
              } 
              })
            .then(res =>{
              if(res.data.msg !== "success"){
                this.$router.push('/')
              }
                this.form = res.data.data;
                this.vehicles = this.form

                for(let i =0;i<this.vehicles.length;i++){
                    this.vehicles[i].id=i
                    console.log(this.vehicles[i].id)
                }
                localStorage.setItem("car",JSON.stringify(this.vehicles));
              
                this.$router.push({
              name: 'product',
            params: {
                  vehicles:this.vehicles
			          }

              })
            
              })
            
        }
        if(value=='2'){
            this.$axios.post('/car/selectAddress',{

                address:'海南省海口市',
            },
            {
              headers:{
                "token":JSON.parse(localStorage.getItem('user')).token
              } 
              })
            .then(res =>{
              if(res.data.msg !== "success"){
                this.$router.push('/')
              }
                this.form = res.data.data;
                this.vehicles = this.form

                for(let i =0;i<this.vehicles.length;i++){
                    this.vehicles[i].id=i
                    console.log(this.vehicles[i].id)
                }
                localStorage.setItem("car",JSON.stringify(this.vehicles));

                this.$router.push({
                name: 'product',
                params: {
                      vehicles:this.vehicles
                    }

                  })
            })
            
        }
        if(value=='3'){
          
            this.$axios.post('/car/selectAddress',{

                address:'河北省廊坊市',

            },
            {
              headers:{
                "token":JSON.parse(localStorage.getItem('user')).token
              } 
              })
            .then(res =>{
              if(res.data.msg !== "success"){
                this.$router.push('/')
              }
                this.form = res.data.data;
                this.vehicles = this.form

                for(let i =0;i<this.vehicles.length;i++){
                    this.vehicles[i].id=i
                    console.log(this.vehicles[i].id)
                }
                localStorage.setItem("car",JSON.stringify(this.vehicles));

            
                this.$router.push({
                name: 'product',
                params: {
                      vehicles:this.vehicles
                    }

                  })
              })
            
        }
    }
          }
  }
  </script>
<style>
.box{
    transform: translateX(150px);
}
</style>
